define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'barrage/index' + location.search,
                    add_url: 'barrage/add',
                    edit_url: 'barrage/edit',
                    del_url: 'barrage/del',
                    multi_url: 'barrage/multi',
                    table: 'barrage',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'live_id', title: __('Live_id')},
                        {field: 'nickname', title: __('Nickname')},
                        {field: 'msg', title: __('Msg')},
                        {field: 'font_size', title: __('Font_size')},
                        {field: 'color', title: __('Color')},
                        {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'user.id', title: __('User.id')},
                        {field: 'user.username', title: __('User.username')},
                        {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'user.mobile', title: __('User.mobile')},
                        {field: 'live.id', title: __('Live.id')},
                        {field: 'live.title', title: __('Live.title')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        danmu: function () {



            //绑定表格
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'barrage/index' + location.search,
                    add_url: '',
                    edit_url: '',
                    del_url: 'barrage/del',
                    multi_url: 'barrage/multi',
                    table: 'barrage',
                }
            });
            var table = $("#table");

            table.bootstrapTable({
                url: $("#table").data('url'),
                method:'get',
                search:false,
                showRefresh:false,
                showToggle:false,
                columns: [
                    {field: 'id', title: '编号'},
                    {field: 'user_id', title: '用户编号'},
                    {field: 'nickname', title: '用户昵称'},
                    {field: 'msg', title: '弹幕内容'},
                    {field: 'create_time', title: '创建时间'},
                    {field: 'operate',
                        title: __('Operate'),
                        table: table,
                        events: Table.api.events.operate,
                        formatter: Table.api.formatter.operate}
                ],
                pagination: true
            });

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});